home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / etc / init.d / powernowd < prev    next >
Encoding:
Text File  |  2008-09-15  |  4.6 KB  |  180 lines

  1. #! /bin/sh
  2. # Init script for powernowd
  3. #
  4. ### BEGIN INIT INFO
  5. # Provides:          powernowd
  6. # Required-Start:    $syslog $local_fs $time
  7. # Required-Stop:     $syslog $local_fs
  8. # Default-Start:     2 3 4 5
  9. # Default-Stop:         1
  10. # Short-Description: Start powernowd .
  11. ### END INIT INFO
  12.  
  13.  
  14. PATH=/sbin:/bin:/usr/sbin:/usr/bin
  15. DAEMON=/usr/sbin/powernowd
  16. NAME=powernowd
  17. DESC=powernowd
  18. OPTIONS="-q"
  19.  
  20. test -x $DAEMON || exit 0
  21.  
  22. # modify the file /etc/default/powernowd if you want to add personal options
  23.  
  24. [ -f /etc/default/$NAME ] && . /etc/default/$NAME
  25.  
  26. # Get lsb functions
  27. . /lib/lsb/init-functions
  28. . /etc/default/rcS
  29.  
  30. if [ "x$VERBOSE" = "xno" ]; then
  31.         MODPROBE_OPTIONS="$MODPROBE_OPTIONS -Q"
  32.         export MODPROBE_OPTIONS
  33. fi
  34.  
  35. set -e
  36.  
  37. load_modules() {
  38.         #stop the kernel printk'ing at all while we load.
  39.         PRINTK=`cat /proc/sys/kernel/printk`
  40.         [ "$VERBOSE" = no ] && echo "1 1 1 1" > /proc/sys/kernel/printk
  41.  
  42.         #build a list of current modules so we don't load a module twice
  43.         LIST=`/sbin/lsmod|awk '!/Module/ {print $1}'`
  44.         
  45.         #get list of available modules
  46.         LOC="/lib/modules/`uname -r`/kernel/drivers/cpufreq"
  47.         if [ -d $LOC ]; then
  48.           MODAVAIL=`( find $LOC -type f -name "*.o" -printf "basename %f .o\n"; \
  49.                    find $LOC -type f -name "*.ko" -printf "basename %f .ko\n" ) | /bin/sh`
  50.         else
  51.           MODAVAIL=""
  52.         fi
  53.  
  54.         
  55.         #echo "Loading cpufreq modules:"
  56.         for mod in $MODAVAIL; do
  57.         #        echo "     $mod"
  58.                 echo $LIST| grep -q -w "$mod" || modprobe $mod >/dev/null || /bin/true
  59.         done
  60.         
  61.         #cpufreq is built in on powerpc; just return
  62.         if [ "`uname -m`" = "ppc" ]; then
  63.                 echo "$PRINTK" > /proc/sys/kernel/printk
  64.                 return 0
  65.         fi
  66.  
  67.  
  68.         #new style detection system
  69.         if [ ! "$FREQDRIVER" = "" ]; then 
  70.                 modprobe "$FREQDRIVER"
  71.         else
  72.             . /usr/share/powernowd/cpufreq-detect.sh
  73.                 [ ! -z "$MODULE" ] && (modprobe "$MODULE"||modprobe "$MODULE_FALLBACK")
  74.         fi
  75.  
  76.         if [ "$USE_OLD_DETECT" = "fish" ]; then
  77.         # now lets load the driver
  78.         if [ ! $FREQDRIVER = "" ]; then 
  79.                 modprobe $FREQDRIVER||true
  80.         fi
  81.         if [ "`uname -m`" = "x86_64" ]; then 
  82.                 modprobe powernow-k8 >/dev/null 2>&1||true
  83.         fi
  84.  
  85.         if [ ! -f /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor ]; then
  86.                 modprobe acpi > /dev/null 2>&1|| true
  87.         fi
  88.         fi
  89.         echo "$PRINTK" > /proc/sys/kernel/printk
  90. }
  91.  
  92. use_ondemand() {
  93.     if [ "$OPTIONS" != "-q" ]; then
  94.         return 1
  95.     fi
  96.     status=1  # return error, if no cpu dirs are found
  97.     for x in /sys/devices/system/cpu/cpu[0-9]*/; do
  98.         if [ ! -d $x ] || [ ! -f $x"cpufreq/scaling_governor" ]; then
  99.             continue
  100.         fi
  101.         echo -n ondemand > $x"cpufreq/scaling_governor"
  102.         status=$?
  103.         if [ $status != 0 ]; then
  104.         return $status
  105.         fi
  106.         # The default behaviour of powernowd is to ignore nice load:
  107.         if [ -f $x"cpufreq/ondemand/ignore_nice_load" ]; then
  108.             echo -n 1 > $x"cpufreq/ondemand/ignore_nice_load"
  109.         fi
  110.     done
  111.     return $status
  112. }
  113.  
  114. check_kernel() {
  115.     CPUFREQ=/sys/devices/system/cpu/cpu0/cpufreq
  116.  
  117.     if [ -f "$CPUFREQ/scaling_governor" ] && \
  118.         [ -f "$CPUFREQ/scaling_available_governors" ] && \
  119.         grep -q userspace "$CPUFREQ/scaling_available_governors"
  120.     then
  121.         return 0
  122.     else
  123.         return 1
  124.     fi
  125. }
  126.  
  127. start() {
  128.            log_begin_msg "Starting $DESC... "
  129.     if use_ondemand
  130.     then
  131.         log_end_msg 0
  132.         return 0
  133.     fi
  134.     if check_kernel
  135.     then
  136.     #       echo "Starting $DESC: "
  137.         start-stop-daemon --start --quiet --oknodo --exec $DAEMON -- $OPTIONS >/dev/null 2>&1 || {
  138.                     status=$?
  139.                     log_end_msg $status
  140.                     return $status
  141.                 }
  142.     else
  143.         log_action_cont_msg "CPU frequency scaling not supported"
  144.     #    echo "required sysfs objects not found!"
  145.     #    echo -e "\tRead /usr/share/doc/powernowd/README.Debian for more information."
  146.     fi
  147.            log_end_msg 0
  148.     return 0
  149. }
  150.  
  151. case "$1" in
  152.   start)
  153.         [ "x$DO_MODULES" = "xyes" -a -f /proc/modules ] && load_modules
  154.     [ "x$DO_MODULES" = "xyes" ] || start
  155.     ;;
  156.   stop)
  157.     log_begin_msg "Stopping $DESC: "
  158.     start-stop-daemon --stop --quiet --oknodo --exec $DAEMON
  159.     for x in /sys/devices/system/cpu/cpu[0-9]*/; do
  160.         if [ -f $x"cpufreq/scaling_governor" ]; then
  161.         echo -n performance > $x"cpufreq/scaling_governor";
  162.         fi
  163.     done
  164.     log_end_msg $?
  165.     ;;
  166.   restart|force-reload)
  167.         $0 stop
  168.     sleep 1
  169.     $0 start
  170.     #echo "$NAME."
  171.     ;;
  172.   *)
  173.     N=/etc/init.d/$NAME
  174.     log_success_msg "Usage: $N {start|stop|restart|force-reload}" >&2
  175.     exit 1
  176.     ;;
  177. esac
  178.  
  179. exit 0
  180.